package com.towexin.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * TODO
 *
 * @author Towexin
 * @version 1.0
 * @date 2020/11/24 16:47
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResultData implements Serializable {
    private static final long serialVersionUID = 7097511417248231168L;

    private Boolean success = Boolean.FALSE;
    private Integer code = null;
    private String msg = "";
    private Object data = null;


    /**
     * 成功响应
     */
    public static ResultData OK() {
        return new ResultData(Boolean.TRUE, 200, "success.");
    }

    public static ResultData OK(Integer code) {
        return new ResultData(Boolean.TRUE, code, "success.");
    }

    public static ResultData OK(Integer code, String msg) {
        return new ResultData(Boolean.TRUE, code, msg);
    }

    public static ResultData OK(Integer code, String msg, Object obj) {
        return new ResultData(Boolean.TRUE, code, msg, obj);
    }

    public static ResultData OK(String msg, Object obj) {
        return new ResultData(Boolean.TRUE, 200, msg, obj);
    }

    public static ResultData OK(Object object) {
        return new ResultData(Boolean.TRUE, 200, "success.", object);
    }


    /**
     * 请求成功，但业务逻辑处理不通过
     */
    public static ResultData NO() {
        return new ResultData(400, "error.");
    }

    public static ResultData NO(String msg) {
        return new ResultData(400, msg);
    }

    public static ResultData NO(Integer code) {
        return new ResultData(code, "error.");
    }

    public static ResultData NO(Integer code, String msg) {
        return new ResultData(code, msg);
    }

    public ResultData(Integer code) {
        super();
        this.code = code;
    }

    public ResultData(Integer code, String msg) {
        super();
        this.code = code;
        this.msg = msg;
    }

    public ResultData(Integer code, String msg, Object res) {
        super();
        this.code = code;
        this.msg = msg;
        this.data = res;
    }

    public ResultData(Boolean success, Integer code, String msg) {
        super();
        this.success = success;
        this.code = code;
        this.msg = msg;
    }
}
